package cn.yuanqiao.web.controller.cqbc;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.cqbc.fileBackupLog.domain.FileBackupLog;
import cn.yuanqiao.cqbc.fileBackupLog.service.IFileBackupLogService;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.page.TableDataInfo;

/**
 * 文件备份日志Controller
 * 
 * @author xy
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/cqbc/fileBackupLog")
public class FileBackupLogController extends BaseController
{
    @Autowired
    private IFileBackupLogService fileBackupLogService;

    /**
     * 查询文件备份日志列表
     */
//    @RequiresPermissions("cqbc:fileBackupLog:list")
    @GetMapping("/list")
    public TableDataInfo list(FileBackupLog fileBackupLog)
    {
        startPage();
        List<FileBackupLog> list = fileBackupLogService.selectFileBackupLogList(fileBackupLog);
        return getDataTable(list);
    }

    /**
     * 导出文件备份日志列表
     */
//    @RequiresPermissions("cqbc:fileBackupLog:export")
    @Log(title = "文件备份日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileBackupLog fileBackupLog)
    {
        List<FileBackupLog> list = fileBackupLogService.selectFileBackupLogList(fileBackupLog);
        ExcelUtil<FileBackupLog> util = new ExcelUtil<FileBackupLog>(FileBackupLog.class);
        util.exportExcel(response, list, "文件备份日志数据");
    }

    /**
     * 获取文件备份日志详细信息
     */
//    @RequiresPermissions("cqbc:fileBackupLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fileBackupLogService.selectFileBackupLogById(id));
    }

    /**
     * 新增文件备份日志
     */
//    @RequiresPermissions("cqbc:fileBackupLog:add")
    @Log(title = "文件备份日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileBackupLog fileBackupLog)
    {
        return toAjax(fileBackupLogService.insertFileBackupLog(fileBackupLog));
    }

    /**
     * 修改文件备份日志
     */
//    @RequiresPermissions("cqbc:fileBackupLog:edit")
    @Log(title = "文件备份日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileBackupLog fileBackupLog)
    {
        return toAjax(fileBackupLogService.updateFileBackupLog(fileBackupLog));
    }

    /**
     * 删除文件备份日志
     */
//    @RequiresPermissions("cqbc:fileBackupLog:remove")
    @Log(title = "文件备份日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fileBackupLogService.deleteFileBackupLogByIds(ids));
    }

    /**
     * 查询列表
     *
     * @author xy
     * @Date 2023-03-01
     */
    @RequestMapping("/restore")
    public AjaxResult backup(FileBackupLog fileBackupLog) {
     //   YqNoticeManage yqNoticeManage = new YqNoticeManage();
        try {

//            yqNoticeManage.setTitle("文件还原");
//            yqNoticeManage.setDetail("将"+filebackupLogResult.getBackupAddress()+"还原到"+filebackupLogResult.getOriginalAddress());
//            yqNoticeManage.setState("1");
//            yqNoticeManage.setLevel("P3");
//            yqNoticeManage.setTargetType("全部");
//            yqNoticeManage.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//            yqNoticeManage.setIsRead("0");
//            yqNoticeManage.setUrl("/filebackupLog/restore");
//            yqNoticeManageMapper.insert(yqNoticeManage);

            fileBackupLogService.restore(fileBackupLog);
//            yqNoticeManage.setState("2");
//            yqNoticeManageMapper.updateById(yqNoticeManage);


        }catch (Exception ex){
            ex.printStackTrace();
//            yqNoticeManage.setState("3");
//            yqNoticeManageMapper.updateById(yqNoticeManage);
            return AjaxResult.error("还原失败");

        }
        return AjaxResult.success();
    }
}
